// subPages/shopPage/addAddress/addAddress.js

const app = getApp();
var untils = require('../../../utils/util');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    region:'所在地区',
    customItem: '全部',
  },
  bindRegionChange(e) {
      console.log('picker发送选择改变，携带值为', e.detail.value)
      this.setData({
          region: e.detail.value,
          sheng:e.detail.value[0],
          shi:e.detail.value[1],
          qu:e.detail.value[2],
      })
  },
  getUname(e){
      this.setData({
          uname: e.detail.value
      })
  },
  getPhone(e){
      this.setData({
          phone: e.detail.value
      })
  },
  bindTextAreaInput(e){
      this.setData({
          address: e.detail.value
      })
  },
  saveAddress(){
      var uname = this.data.uname;
      var phone = this.data.phone;
      var sheng = this.data.sheng;
      var shi = this.data.shi;
      var qu = this.data.qu;
      var userid = app.globalData.userId;
      var address = this.data.address;
      var data = {
        name:uname,
        userid:userid,
        address:address,
        sheng:sheng,
        shi:shi,
        qu:qu,
        phone:phone
      }
      if(uname == undefined||phone == undefined||sheng == undefined|| shi==undefined||qu == undefined ||address == undefined){
          wx.showToast({
              title:'请将收货人信息填写完整！',
              icon:'none',
              duration:1000
          })
      }else{
          console.log(uname,phone,sheng,shi,qu,userid,address);
          untils.sendAjax(app.globalData.apiUrl+'/add_address','GET',function(res){
              console.log(res);
              if(res.data == 1){
                wx.showToast({
                    title:'收货信息保存成功',
                    icon:'success',
                    duration:1000
                })
                setTimeout(function(){
                  wx.navigateBack({
                      delta:1
                  })
                },1000)
              }
          },data)
      }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
